﻿Imports Hinshelwood.TFSStickyBuddy.Modules.Interfaces
Imports Microsoft.Practices.Composite.Wpf.Commands
Imports Infragistics.Windows.Ribbon

Namespace Controlers


    Public Class ThemeController
        Implements IThemeController


        Private Shared m_ChangeThemeCommand As DelegateCommand(Of ThemeItem)
        Private m_ThemeService As IThemeService
        Private m_currentTheme As ResourceDictionary

        Public Property ChangeThemeCommand() As Microsoft.Practices.Composite.Wpf.Commands.DelegateCommand(Of ThemeItem) Implements Interfaces.IThemeController.ChangeThemeCommand
            Get
                Return m_ChangeThemeCommand
            End Get
            Set(ByVal value As Microsoft.Practices.Composite.Wpf.Commands.DelegateCommand(Of ThemeItem))
                m_ChangeThemeCommand = value
            End Set
        End Property

        Public Sub New(ByVal ThemeService As IThemeService)
            m_ThemeService = ThemeService
            ' Set commands
            m_ChangeThemeCommand = New DelegateCommand(Of ThemeItem)(AddressOf OnChangeThemeExecute)
        End Sub

        Private Sub OnChangeThemeExecute(ByVal theme As ThemeItem)
            ThemeService.SetTheme(theme)
        End Sub

        Public ReadOnly Property ThemeService() As Interfaces.IThemeService Implements Interfaces.IThemeController.ThemeService
            Get
                Return m_ThemeService
            End Get
        End Property

        Public Sub TrySetTheme(ByVal theme As ThemeItem) Implements Interfaces.IThemeController.TrySetTheme
            OnChangeThemeExecute(theme)
        End Sub

        Private Sub OnThemeMouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs) Implements Interfaces.IThemeController.OnThemeMouseEnter
            Dim x As ThemeItem = CType(sender, RadioButtonTool).CommandParameter
            ThemeService.PreviewTheme(x)
        End Sub

        Private Sub OnThemeMouseLeave(ByVal sender As Object, ByVal e As MouseEventArgs) Implements Interfaces.IThemeController.OnThemeMouseLeave
            ThemeService.PreviewTheme(Nothing)
        End Sub

    End Class

End Namespace